// pages/dingyue/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    zclist: [],
    zcintPageSize: 10,
    zcintCurrPage: 1,
    zcintPageCount: 0,
    zcshow: false,
    pmlist: [],
    pmintPageSize: 10,
    pmintCurrPage: 1,
    pmintPageCount: 0,
    pmshow: false,
    bjlist: [],
    bjintPageSize: 10,
    bjintCurrPage: 1,
    bjintPageCount: 0,
    bjshow: false,
    more: false,
    box: 1,
    isLogin: false,
    zcnone: false,
    pmnone: false,
    hqnone: false,
    IsQx: 0,
    hqtishi: false,
    shuaxin: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  change: function (r) {
    var status = r.currentTarget.dataset.sta;
    if (this.data.IsQx == 0 && status == 3) {
      this.setData({
        hqtishi: true
      })
      return false
    }
    this.setData({
      box: status,
      zcshow: false,
      pmshow: false,
      bjshow: false,
    })
    if (status == 1 && this.data.zclist.length == 0) {
      this.getzichan();
    }
    if (status == 2 && this.data.pmlist.length == 0) {
      this.getpaimai();
    }
    if (status == 3 && this.data.bjlist.length == 0) {
      this.getbaojia();
    }

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {




  },
  quxiao: function () {
    this.setData({
      hqtishi: false
    })
  },
  none: function () {
    // body...
  },
  fuwudianhua: function () {
    wx.makePhoneCall({
      phoneNumber: '0311-87106666'
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 自定义tabbar切换
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 3
      })
    };


    this.setData({
      isLogin: app.checkFjLogin()
    })
    if (app.checkFjLogin()) {
      var status = this.data.box
      if (status == 1 && this.data.zclist.length == 0) {
        this.getzichan();
      }
      if (status == 2 && this.data.pmlist.length == 0) {
        this.getpaimai();
      }
      if (status == 3 && this.data.bjlist.length == 0) {
        this.getbaojia();
      }
      if (status == 1 && this.data.shuaxin) {
        this.setData({
          shuaxin: false,
          zclist: [],
          zcintPageSize: 10,
          zcintCurrPage: 1,
          zcintPageCount: 0,
        })
        this.getzichan();
      }
      if (status == 2 && this.data.shuaxin) {
        this.setData({
          shuaxin: false,
          pmlist: [],
          pmintPageSize: 10,
          pmintCurrPage: 1,
          pmintPageCount: 0,
        })
        this.getpaimai();
      }
      if (status == 3 && this.data.shuaxin) {
        this.setData({
          shuaxin: false,
          bjlist: [],
          bjintPageSize: 10,
          bjintCurrPage: 1,
          bjintPageCount: 0,
        })
        this.getbaojia();
      }
      this.getFeijiu_Get_BjDyKeyList()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  getFeijiu_Get_BjDyKeyList: function () {
    var that = this;
    var FjLoginLog = wx.getStorageSync('FjLoginLog');
    var api_input = {
      uid: FjLoginLog.UID
    }
    app.getDaoPostN('api/FeijiuApp/Feijiu_Get_BjDyKeyList', api_input, function (r) {

      that.setData({
        IsQx: r.data.IsQx
      })
    })
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.box == 1) {
      var intPageCount = this.data.zcintPageCount;
      var intCurrPage = this.data.zcintCurrPage;
      if (intCurrPage < intPageCount) {
        this.setData({
          zcintCurrPage: intCurrPage + 1
        })
        this.getzichan();
      } else {
        this.setData({
          more: true
        })
      }
    }
    if (this.data.box == 2) {
      var intPageCount = this.data.pmintPageCount;
      var intCurrPage = this.data.pmintCurrPage;
      if (intCurrPage < intPageCount) {
        this.setData({
          pmintCurrPage: intCurrPage + 1
        })
        this.getpaimai();
      } else {
        this.setData({
          more: true
        })
      }
    }
    if (this.data.box == 3) {
      var intPageCount = this.data.bjintPageCount;
      var intCurrPage = this.data.bjintCurrPage;
      if (intCurrPage < intPageCount) {
        this.setData({
          bjintCurrPage: intCurrPage + 1
        })
        this.getbaojia();
      } else {
        this.setData({
          more: true
        })
      }
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getzichan: function () {
    var FjLoginLog = wx.getStorageSync('FjLoginLog');
    var api_input = {
      uid: FjLoginLog.UID,
      intPageSize: this.data.zcintPageSize,
      intCurrPage: this.data.zcintCurrPage,
      strRSA: app.data.strRSA
    }
    var that = this;
    app.getDaoPost('api/FeijiuApp/Post_FJ_GetZCDingYueListALL', api_input, function (r) {
      console.log(r)
      var list1 = that.data.zclist.concat(r.data.data);
      if (r.code == 200) {
        if (api_input.intCurrPage == 1 && r.data.data.length == 0) {
          that.setData({
            zcshow: true
          })
        } else {
          that.setData({
            zcshow: false
          })
        }
        that.setData({
          zclist: list1,
          zcintPageCount: r.data.intPageCount
        })
        if (r.data.intRecordCount < 10 && r.data.intRecordCount > 0) {
          that.setData({
            more: true
          })
        }
      }
    })
  },
  getpaimai: function () {
    var FjLoginLog = wx.getStorageSync('FjLoginLog');
    var api_input = {
      uid: FjLoginLog.UID,
      intPageSize: this.data.pmintPageSize,
      intCurrPage: this.data.pmintCurrPage
    }
    var that = this;
    app.getDaoPost('api/FeijiuApp/Feijiu_Get_PMDingYueListALL', api_input, function (r) {
      var list1 = that.data.pmlist.concat(r.data.data);
      console.log(r)
      for (var i = 0; i < list1.length; i++) {
        var status = new Date(list1[i].endtime.replace(/-/g, "/")) - new Date();
        if (list1[i].time == '待定') {
          list1[i].endtime = '待定';
        }
        if (status > 1 || list1[i].endtime == '待定') {
          list1[i].status = 1
        } else {
          list1[i].status = 0
        }
      }
      if (r.code == 200) {
        if (api_input.intCurrPage == 1 && r.data.data.length == 0) {
          that.setData({
            pmshow: true
          })
        } else {
          that.setData({
            pmshow: false
          })
        }
        that.setData({
          pmlist: list1,
          pmintPageCount: r.data.intPageCount
        })
        if (r.data.intRecordCount < 10 && r.data.intRecordCount > 0) {
          that.setData({
            more: true
          })
        }
      }
    })
  },
  getbaojia: function () {
    var FjLoginLog = wx.getStorageSync('FjLoginLog');
    var api_input = {
      uid: FjLoginLog.UID,
      intPageSize: this.data.bjintPageSize,
      intCurrPage: this.data.bjintCurrPage
    }
    var that = this;
    app.getDaoPost('api/FeijiuApp/Feijiu_Get_BjDyListALL', api_input, function (r) {
      if (r.code == 200) {
        if (api_input.intCurrPage == 1 && r.data.data.length == 0) {
          that.setData({
            bjshow: true
          })
        } else {
          that.setData({
            bjshow: false
          })
        }
        for (var i = 0; i < r.data.data.length; i++) {
          r.data.data[i].BJ_datetime = app.dateformatT(r.data.data[i].BJ_datetime, 10)
        }
        var list1 = that.data.bjlist.concat(r.data.data);
        that.setData({
          bjlist: list1,
          bjintPageCount: r.data.intPageCount
        })
        if (r.data.intRecordCount < 10 && r.data.intRecordCount > 0) {
          that.setData({
            more: true
          })
        }
      }
    })
  },
  // 拍卖去详细页
  toPmView: function (e) {
    wx.navigateTo({
      url: '../zhaobiaogonggao/detailed?uuid=' + e.currentTarget.dataset.uuid
    })
  },
  baoming: function (e) {
    wx.navigateTo({
      url: '../zhaobiaogonggao/baoming?uuid=' + e.currentTarget.dataset.uuid + '&name=' + e.currentTarget.dataset.name
    })
  },
  toZcview: function (e) {
    wx.navigateTo({
      url: '/packageA/pages/zichanchuzhi/detailed?gqid=' + e.currentTarget.dataset.gqid
    })
  },
  tokeylist: function () {
    var that = this;
    wx.getSetting({
      withSubscriptions: true,
      success(r) {
        if (r.subscriptionsSetting.mainSwitch) {
          wx.navigateTo({
            url: 'keylist?type=' + that.data.box
          })
        } else {
          wx.requestSubscribeMessage({
            tmplIds: ['z5dASgSZjyLPjj0uKKRFZ0fpTZBj3bC36EB3jsRKpGw'],
            success(res) {

            },
            complete: function (res) {
              wx.navigateTo({
                url: 'keylist?type=' + that.data.box
              })
            }
          })
        }
      }
    })
  },
  toBjview: function (e) {
    wx.navigateTo({
      url: '../baojiayuce/bjinfo?type=bj&nid=' + e.currentTarget.dataset.bjid
    })
  },
  toLogin: function () {
    wx.navigateTo({ url: '../../pages/login/index' });
  }
})